package online.abor.day12_study.provider_consumer.baozi;

import java.util.Random;

public class Zuo extends Thread {
    private Baozi baozi;

    public Zuo(String name, Baozi baozi) {
        super(name);
        this.baozi = baozi;
    }

    @Override
    public void run() {
        while (true) {
            synchronized (baozi) {
                if (baozi.isFlag()) {
                    try {
                        baozi.wait();
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                } else {
                    baozi.setPi(new String[]{"厚皮", "薄皮"}[new Random().nextInt(2)]);
                    baozi.setXian(new String[]{"牛肉", "猪肉"}[new Random().nextInt(2)]);
                    System.out.println(Thread.currentThread().getName() + "做包子[" + baozi + "]");
                    baozi.setFlag(true);
                    // baozi.notify();
                    baozi.notifyAll();
                    try {
                        Thread.sleep(1000);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            }
        }
    }
}
